﻿using Prism.Events;
using RoboAssembleX.Application.AddBoard1;
using RoboAssembleX.Application.AddBoard2;
using RoboAssembleX.Application.AddGlass;
using RoboAssembleX.Application.AddGlass1;
using RoboAssembleX.Application.AddNeedle2;
using RoboAssembleX.Application.Common;
using RoboAssembleX.Application.Robot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RoboAssembleX.Application.ActionJobs
{
    public class ActionJob51 : BindableBase, IActionJob
    {
        private string name = "基片1到基片2"; public string Name { get => name; }
        private bool running; public bool Running { get => running; set { running = value; RaisePropertyChanged(); } }
        private bool enable = true; public bool Enable { get => enable; set { enable = value; RaisePropertyChanged(); } }
        private int priority = 0;
        private readonly IEventAggregator eventAggregator;
        private readonly AddBoard1Model addBoard1Model;
        private readonly AddBoard1Service addBoard1Service;
        private readonly AddBoard2Model addBoard2Model;

        public ActionJob51(IEventAggregator eventAggregator, AddBoard1Model addBoard1Model ,AddBoard1Service addBoard1Service, AddBoard2Model addBoard2Model)
        {
            this.eventAggregator = eventAggregator;
            this.addBoard1Model = addBoard1Model;
            this.addBoard1Service = addBoard1Service;
            this.addBoard2Model = addBoard2Model;
        }

        public int Priority { get => priority; set { priority = value; RaisePropertyChanged(); } }

        public bool IsReady
        {
            get
            {
                // 引线允许取料  引线料位有料
                return addBoard1Model.AllowRemove && addBoard2Model.AllowPut
                     && !addBoard2Model.InPosUsed;
            }
        }

        public async Task RunActionAsync()
        {
            Running = true;
            eventAggregator.GetEvent<MessageEvent>().Publish(new MessageEventArgs("启动基片1推模!", 1));
            addBoard1Service.Action();
            await Task.Delay(1000);
            Running = false;
        }
    }
}
